<?php
//$self = str_replace('/index.php','',$_SERVER['PHP_SELF']);
if(LOCALHOST) {
	$ref = isset($_GET['ref']) ? $_GET['ref'] : GLOBAL_URL.substr($_SERVER['PHP_SELF'],1).'?'.$_SERVER['QUERY_STRING'];
} else {
	$ref = isset($_GET['ref']) ? $_GET['ref'] : ADMINER_URL.'index.php'.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
}
include_once 'inc_modules_path.php';
?>
<form class="form-inline" action="<?php echo site_urlc($this->class.'/index/'.$this->cid); ?>" method="GET">
	<?php if ($ctype = list_coltypes($this->cid,0,'ctype')) { ?>
		<?php
			if (isset($_GET['ctype']) AND is_numeric($_GET['ctype']) AND $_GET['ctype']) {
				echo ui_btn_select('ctype',set_value("ctype",$_GET['ctype']),$ctype);
			}else{
				echo ui_btn_select('ctype',set_value("ctype"),$ctype);
			}
		?>
	<?php } ?>
	<span>申请人姓名:</span>
	<input type="text" class="" name="uname"
		   value="<?php echo $this->input->get('uname') ?>">
	<span>申请状态<?php echo $this->input->get('status')?>:</span>
	<select class="select" name="status">
		<?php $status = $this->input->get('status')?>
		<option value="3"  <?php echo $this->input->get('status') == 3 ? 'selected':'' ?>>全部</option>
		<option value="0"  <?php echo isset($_GET['status']) && $_GET['status'] == 0 ? 'selected':'' ?>>正在审核</option>
		<option value="1" <?php echo $this->input->get('status') == 1 ? 'selected':'' ?>>审核不通过</option>
		<option value="2" <?php echo $this->input->get('status') == 2 ? 'selected':'' ?>>审核通过</option>
	</select>
	<span>原企业全称:</span>
	<input type="text" class="" name="old_com_name"
		   value="<?php echo $this->input->get('old_com_name') ?>">
	<span>新企业全称:</span>
	<input type="text" class="" name="com_name"
		   value="<?php echo $this->input->get('com_name') ?>">
	<input class="btn" type="submit" value="检索">
	<a href="<?php echo site_urlc('coltypes/index/').'&field=ctype&rc='.$this->class; ?>" class="btn">分类管理</a>
</form>
<span>未处理数<?php echo $total?></span>
<p></p>
<div class="clearfix"><p></p></div>

<div class="boxed">
	<div class="boxed-inner seamless">

<table class="table table-striped table-hover select-list">
	<thead>
		<tr>
			<th class="width-small"><input id='selectbox-all' type="checkbox" > </th>
			<th>姓名</th>
			<th>手机号</th>
			<th>申请类型</th>
			<th>原身份类型</th>
			<th>原企业全称</th>
			<th>原企业简称</th>
			<th>变更企业简称</th>
			<th>变更企业全称</th>
			<th>变更身份类型</th>
			<th>变更职位</th>
			<th>新名片</th>
			<th>申请状态</th>
			<th>申请时间</th>
			<th class="span1">操作</th>
		</tr>
	</thead>
	<tbody class="sort-list">
		<?php foreach ($list as $v):?>
		<tr data-id="<?php echo $v['id'] ?>" data-sort="<?php echo $v['sort_id'] ?>">
			<td><input class="select-it" type="checkbox" value="<?php echo $v['id']; ?>" ></td>
			<td>
				<?php echo $v['username']?>
			 </td>
			<td> <?php echo $v['phone'] ?></td>
			<td> <?php $title = get_ctype_title($v['ctype']); echo $title['title'] ?></td>
			<td> <?php $title = get_ctype_title($v['uctype']); echo $title['title'] ?></td>
			<td> <?php echo $v['old_com_name'] ? $v['old_com_name'] : ''?></td>
			<td> <?php echo $v['old_com_short'] ? $v['old_com_short'] : ''?></td>
			<td> <?php echo $v['com_name'] ?></td>
			<td> <?php echo $v['com_short'] ?></td>
			<td> <?php $title = get_ctype_title($v['actype']); echo $title['title']  ?></td>
			<td> <?php echo $v['position'] ? $v['position'] : '' ?></td>
			<td>
				<?php if($v['thumb']) {?>
				<a class="fancybox-img" href="<?php echo UPLOAD_URL. str_replace('thumbnail/', '', $v['thumb']); ?>" title="<?php echo $v['com_name'] ?>">
					<img src="<?php echo UPLOAD_URL.$v['thumb'] ?>" alt="<?php echo $v['com_name'];?>">
				</a>
				<?php }?>
			</td>
			<td> <?php echo $v['status'] ? ($v['status'] ==1 ? '审核未通过':'审核通过'):'审核中' ?></td>

			<td> <?php echo date("Y/m/d H:i:s",$v['timeline']); ?> </td>
			<td>
				<div class="btn-group">
					<?php if($v['status'] == 0) {?>
						<a class='btn btn-small' href=" <?php echo site_url( $this->router->class.'/one/'.$this->cid.'?id='.$v['id'].'&status=1'.'&ref='.base64_encode($ref)) ?> " onclick="javascript:return check_one()"> 审核不通过 </a>
						<a class='btn btn-small' href=" <?php echo site_url( $this->router->class.'/one/'.$this->cid.'?id='.$v['id'].'&status=2'.'&ref='.base64_encode($ref)) ?> " onclick="javascript:return check_one()">审核通过</a>
					<?php } ?>
				</div>
			</td>
		</tr>
		<?php endforeach;?>
	</tbody>
</table>

	</div>
</div>

<div class="btn-group">
	<a id='select-all' class='btn' href="#"> <i class=""></i> <?php echo lang('select_all') ?> </a>
	<a id='unselect-all' class='btn hide' href="#"> <i class=""></i> <?php echo lang('unselect') ?> </a>
	<a id="btn-status" class='btn btn-status' href="javascript:void(0) ;" data-status='2'>审核通过</a>
	<a id="btn-status" class='btn btn-status' href="javascript:void(0) ;"  data-status='1'>审核未通过</a>
</div>

<?php echo $pages; ?>

<script>
require(['adminer/js/ui'],function(ui){
	var identity = {
		url_del: "<?php echo site_urlc('identity/delete'); ?>"
		,url_audit: "<?php echo site_urlc('identity/audit'); ?>"
		,url_flag: "<?php echo site_urlc('identity/flag'); ?>"
		,url_sortid: "<?php echo site_urlc('identity/sortid'); ?>"
		,url_sort_change: "<?php echo site_urlc('identity/sort_change'); ?>"
		,url_copy: "<?php echo site_urlc('identity/copypro'); ?>"
	};
	ui.fancybox_img();
	ui.btn_delete(identity.url_del);		// 删除
	ui.btn_audit(identity.url_audit);	// 审核
	ui.btn_flag(identity.url_flag);		// 推荐
	// ui.sortable(identity.url_sortid);	// 排序  拖动排序和序号排序在firefox中有bug
	ui.sort_change(identity.url_sort_change); // input 排序
	ui.btn_copy(identity.url_copy);    // 热门审核
});
</script>
<script>
    function check_one() {
        var msg = "请确认您的操作";
        if (confirm(msg)==true){
            return true;
        }else{
            return false;
        }
    }
	require(['jquery'],function($){
        var url = '<?php echo site_urlc('identity/status'); ?>';
		$('.selectpicker').on('change',function(){
			var val = $(this).val();
			var uid = $(this).attr('data-id');
			$.ajax({
				url: url,
				type: 'POST',
				dataType: 'json',
				data: {
					ids:uid,
					status:val,
					_cfs:$.cookie('_cfc')
				}
			}).done(function(data) {
				console.log("success");
				var msg = {
					title:'',
					text:data.msg,
					type:'',
					delay:3000
				};
				if (data.status == 1 ) {
					msg.title = "OK!";

				}else{
					msg.title = "错误！";
					msg.type = 'error';
				}
				$.pnotify(msg);
			}).fail(function(XMLHttpRequest, textStatus, errorThrown){
				var m = XMLHttpRequest.responseJSON;
				$.pnotify({
					title:"错误提示！",
					text:m.msg,
					type:"error",
					animation: 'fade'
				});
			}).always(function() {
				console.log("complete");
			});
		});
		$('.btn-status').click(function() {
			var status = $(this).attr('data-status');
			var ids = "";
			// 上两层
			var row = $('.select-list input:checked[type="checkbox"].select-it').parent().parent();
			$('.select-list input:checked[type="checkbox"].select-it').each(function(i,item){
				if (i) {
					ids += ',';
				}
				ids += item.value;
			});
			if(!ids) {
				bootbox.alert('还没有做任何的选择！');
				return false;
			}
			var audit = {
				ids:ids,
				status:status,
				_cfs:$.cookie('_cfc')
			};
			//console.log(audit);
			$.ajax({
				url: url,
				type: 'POST',
				dataType: 'json',
				data: audit
			}).done(function(data) {
				console.log("success");
				var msg = {
					title:'',
					text:data.msg,
					type:'',
					delay:3000
				};
				if (data.status == 1 ) {
					msg.title = "OK!";

				}else{
					msg.title = "错误！";
					msg.type = 'error';
				}
				$.pnotify(msg);
			}).fail(function(XMLHttpRequest, textStatus, errorThrown){
				var m = XMLHttpRequest.responseJSON;
				$.pnotify({
					title:"错误提示！",
					text:m.msg,
					type:"error",
					animation: 'fade'
				});
			}).always(function() {
				console.log("complete");
			});
		});
	});
</script>
